package org.cunamas.core.dao.impl;

import javax.sql.DataSource;

import org.cunamas.core.dao.DynamicTextDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;


@Component
public class DinamicTextDaoJdbcImpl implements DynamicTextDao  {
	
	private JdbcTemplate jdbcTemplate;
	
	@Autowired
	public void setJdbcTemplate(DataSource dataSource) {
		 this.jdbcTemplate = new JdbcTemplate(dataSource);
	}
		
	
	public Integer countComiteGestion(String ubigeo){
		String sql = "select count(*) from dbo.TComiteGestion where codubigeo like '" +
				ubigeo +
				"%' and  codprg='001' and est='1' ";
		return jdbcTemplate.queryForInt(sql);
	}
	
	
	public Integer countModulos(String ubigeo){
		String sql="select count(*) from dbo.TModuloWawawasi sa " +
				" inner join dbo.TComiteGestion C on SA.CODPRG=C.CODPRG and SA.CODSED=C.CODSED and SA.CODCOMGES=C.CODCOMGES" +
				" inner join dbo.TLocalWawawasi L on SA.CODPRG=L.CODPRG and SA.CODSED=L.CODSED and SA.CODCOMGES=L.CODCOMGES " +
				" and SA.CODLOCWAW=L.CODLOCWAW  " +
				" inner join dbo.TModuloWawawasi M on SA.CODPRG=M.CODPRG and SA.CODSED=M.CODSED and SA.CODCOMGES=M.CODCOMGES " +
				" and SA.CODLOCWAW=M.CODLOCWAW and SA.CODMODWAW=M.CODMODWAW" +
				" and C.codubigeo like '" +
				ubigeo +
				"%' and  C.codprg='001' and c.est='1' ";
		
		return jdbcTemplate.queryForInt(sql);
	}

}
